<template>
	<view>
		<video
			class="video"
			id="myVideo"
			:src="url"
			:controls="controls"
			autoplay="true"
		/>
	</view>
</template>

<script>
import {
	mapState,
} from 'vuex';
import { updateLive, updateLiveByParent } from '@/api/common.js'
	export default {
		data() {
			return {
				url: '',
				controls: true,
				id: ''
			}
		},
		computed: {
			...mapState({
				appType: state => state.app.appType,
			}),
		},
		onLoad(options) {
			console.log(options)
			//"https://h5.youzan.com/wscvis/knowledge/index?kdt_id=99491309&page=livedetail&alias=369chqneb0urx9a&qr=paidcontent_369chqneb0urx9a&shopAutoEnter=1"
			uni.setNavigationBarTitle({
				title: options.title
			})
			this.url = decodeURIComponent(options.url);
			this.id = options.id;
			if (this.$u.test.isEmpty(options.controls)) {
				this.controls = false;
			}
			this.update = options.update
		},
		onReady() {
			var wv;
			  // #ifdef APP-PLUS
			  console.log('App plus2')
			  var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象
			  setTimeout(function() {
				wv = currentWebview.children()[0]
				wv.setStyle({scalable:true})
			  }, 1000); //如果是页面初始化调用时，需要延时一下
			  // #endif
		},
		onUnload() {
			this.videoContext.stop();
			clearInterval(this.cameraInterval)
		},
		onReady() {
			this.videoContext = uni.createVideoContext('myVideo')
			if (this.update !== 'false') {
				this.setInterval()
				this.updateLive()
			}
		},
		methods: {
			setInterval() {
				this.cameraInterval = setInterval(() => {
					this.updateLive()
				}, 1000 * 60 * 5);

			},
			updateLive() {
				let getF = updateLiveByParent;
				if (this.appType === 'app-tch' || this.appType === 'mp-tch') {
					getF = updateLive;
				}
				getF({liveRoomId: this.id}).then(res => {})
			}
		}
	}
</script>

<style lang="scss">
	.video{
		width: 100%;
	}
</style>
